package day4;

import java.util.Scanner;

public class demo1 {
    public static void main(String[] args) {
        int x1=0;
        int x2=1;
        int x3=1;
        Scanner scanner=new Scanner(System.in);
        int x=scanner.nextInt();
        while(x2<=x){
            x1=x2;
            x2=x3;
            x3=x1+x2;
        }
        int ret=Math.min(Math.abs(x-x1),Math.abs(x-x2));
        System.out.println(ret);
    }
}
